// 参考：https://blog.csdn.net/weixin_52372879/article/details/127588495：微信小程序自定义tabbar【中间凸起样式】
// 项目开源地址: https://gitee.com/OHUHO/mini-program-components.git
const app = getApp();
Component({
  data: {
    tabBarHeight: app.globalData.tabBarHeight,
    safeBottom: app.globalData.safeBottom,
    selected: 0,
    color: "#CBCAC9",
    selectedColor: "#FF7300",
    backgroundColor: "#ffffff",
    show: true,
    list: [{
      pagePath: "/pages/home/home",
      text: "首页",
      selectedIconPath: "/image/1-home2.png",
      iconPath: "/image/1-home1.png"
    },
    {
      pagePath: "/pages/course/course",
      text: "课程",
      selectedIconPath: "/image/2-course2.png",
      iconPath: "/image/2-course1.png"
    },
    {
      selectedIconPath: "/image/3-speech2.png",
      iconPath: "/image/3-speech1.png",
      bulge:true
    },
    {
      pagePath: "/pages/treasurebox/treasurebox",
      text: "宝箱",
      selectedIconPath: "/image/4-treasurebox2.png",
      iconPath: "/image/4-treasurebox1.png"
    },
    {
      pagePath: "/pages/mine/mine",
      text: "我的",
      selectedIconPath: "/image/5-mine2.png",
      iconPath: "/image/5-mine1.png"
    }],
  },
  attached() {},
  methods: {
    switchTab(e) {
      console.log('点击tab-bar栏按钮：', e.currentTarget.dataset)
      const dataset = e.currentTarget.dataset
      const path = dataset.path
      const index = dataset.index
      //正常的tabbar切换界面
      if (index !== this.data.selected && !this.data.list[index].bulge) {
        wx.switchTab({
          url: path
        })
        this.setData({
          selected: index
        })
      }
      else if(index !== this.data.selected && this.data.list[index].bulge){
        // this.setData({
        //   selected: index
        // })
        console.log('点击首页中间的语音按钮！')
        if(wx.getStorageSync('accessTokenData').accessToken){
            wx.navigateTo({
                url: '/pages/search/search',
            })
          }
          else{
            wx.showToast({
              title: '请前往“我的”授权登录！',
              icon: "none",
              duration: 2000
            })
          }
      }
    }
  }
})